package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.GroupMember;
import com.zxkj.commonpatrol.model.entity.itemPicEntity;
import com.zxkj.commonpatrol.model.entity.itemVioceEntity;
import com.zxkj.commonpatrol.model.response.MediaInfoResponse;
import com.zxkj.commonpatrol.repoisity.ExceptionDetailRepoisity;
import com.zxkj.commonpatrol.repoisity.ShowMediaDetailRepoisity;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class ShowMediaDetailViewModel extends BaseViewModel<ShowMediaDetailRepoisity> {

    public StateLiveData<List<MediaInfoResponse>> MediaInfoResponses=new StateLiveData<>();
//    public StateLiveData<  HashMap<Integer,List<itemPicEntity>>> picData=new StateLiveData<>();
    public StateLiveData< List<itemPicEntity>> picData=new StateLiveData<>();

    public StateLiveData<  HashMap<Integer,List<itemVioceEntity>>> viceData=new StateLiveData<>();
    public ShowMediaDetailViewModel(@NonNull Application application) {
        super(application);
    }
    /**
     * 获取问题对应的媒体数据信息
     *
     * @param alarmId 报警记录AlarmId
     */
    public void getAlarmLogMedioInfo(String alarmId) {
        mRepository.getAlarmLogMedioInfo(alarmId, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                List<MediaInfoResponse> mediaInfoResponse = (List<MediaInfoResponse>) o;
                if (mediaInfoResponse != null) {
                    MediaInfoResponses.postSuccess(mediaInfoResponse);

                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                MediaInfoResponses.postFailure(404,(String)t1);
            }
        });
    }

    /**
     * 下载语音数据
     *
     * @param fileName 文件名
     * @param path     文件路径
     * @param VoiceId  对应AlarmLogVoice表ID 字段
     * @param GroupId  语音所属媒体组1/媒体组2
     * @param index    语音在媒体组中的位置索引
     */
    public void downLoadVoice(String fileName, String path, String VoiceId, int GroupId, int index,List<MediaInfoResponse.MediaVoice> mediaVoices) {




        mRepository.DownLoadVoice(fileName, path, VoiceId, GroupId, index, mediaVoices,new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                HashMap<Integer,List<itemVioceEntity>> listHashMap=( HashMap<Integer,  List<itemVioceEntity>>)o;
                if (listHashMap!=null){
                    viceData.postSuccess(listHashMap);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                viceData.postFailure(404,(String)t1);
            }
        });
    }

       /**
     * 下载图片数据
     *
     * @param fileName 文件名
     * @param path     文件路径
     * @param PhotoId  对应AlarmLogPhoto表ID 字段
     * @param GroupId  图片所属媒体组1/媒体组2
     * @param index    图片在媒体组中的位置索引
     */
    public void downLoadPhoto(String fileName, String path, String PhotoId, int GroupId, int index,List<MediaInfoResponse.MediaPhoto> mediaVoices) {


        mRepository.DownLoadPhoto(fileName, path, PhotoId, GroupId, index,mediaVoices, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                HashMap<Integer,List<itemPicEntity>> listHashMap=( HashMap<Integer,  List<itemPicEntity>>)o;
                List<itemPicEntity> itemPicEntityList = (List<itemPicEntity>) o;
                if (listHashMap!=null){
//                    picData.postSuccess(listHashMap);
                    picData.postSuccess(itemPicEntityList);

                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                picData.postFailure(404,(String)t1);
            }
        });
    }

    /**
     * 下载视频
     *
     * @param fileName 文件名
     * @param path     文件路径
     * @param VedioId  对应AlarmLogVedio表ID 字段
     * @param GroupId  视频所属媒体组1/媒体组2
     * @param index    视频在媒体组中的位置索引
     */
    public void downLoadVedio(String fileName, String path, String VedioId, int GroupId, int index) {
        mRepository.DownLoadVedio(fileName, path, VedioId, GroupId, index, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {

            }
        });
    }




}
